package ltq.dao;

import ltq.model.BrandGenderAVGAge;
import ltq.util.DatabaseUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class TestDao {
    public List<BrandGenderAVGAge> TestFunction(){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<BrandGenderAVGAge> list=new ArrayList<>();
        try {
            con= DatabaseUtil.getConnection();
            ps = con.prepareStatement("select t.rBrand ,t.rSex ,t.rAverageAge  from TAAresult t ,TAAresultTemp temp where t.rBrand =temp.rBrand");
            rs = ps.executeQuery();
            while(rs.next()){
                list.add(new BrandGenderAVGAge(rs.getString("rBrand"),
                                rs.getString("rSex"),
                                rs.getDouble("rAverageAge")
                        )
                );
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return list;
    }
}
